package com.romotc.qqrobot.webqq.qqInterfaceCatching;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Map;

import com.romotc.qqrobot.bean.QQLogedin;
import com.romotc.qqrobot.bean.RobotUser;
import com.romotc.qqrobot.bean.RobotUserService;
import com.romotc.qqrobot.bean.RobotUserSubQq;
import com.romotc.qqrobot.bean.RobotUserSubQqService;
import com.romotc.scache.RequestSpy;
import com.romotc.scache.WebConnection;
/**
 * 对子号或者机器人管理员的号码退出进行拦截
 * 不进行退出 启动机器人的滴答 和 Poll2线程以保证在线状态和消息获取
 * @author Administrator
 *
 */
public class Logout2__Catching extends QQUrlBodyCatching {
	
	/**
	 * 调用条件：是子号或supperQQ
	 */
	@Override
	public boolean checkChatchingCondition(RequestSpy requestSpy) {
		QQLogedin curQQ = getCurQqLogedIn(requestSpy);
		if(curQQ == null) 
			return false;
		
		//检查是否为子号 或者supperQQ
		RobotUser robotUser = RobotUserService.qryUser(curQQ.getUin());
		if(robotUser != null 
				|| RobotUserSubQqService.qrySubQQ(curQQ.getUin()) != null) {
			//启动滴答线程
			curQQ.startKeepOnlineThread();
			
			return true;
			
		}
			

		return false;
	}
	
	
	@Override
	String getHackReqBodyStr(RequestSpy requestSpy, Map<String, Object> var) {
		// TODO Auto-generated method stub
		return "{\"retcode\":0,\"result\":\"dida\"}";
	}

	@Override
	ArrayList<String> hackRequestHeader(RequestSpy requestSpy, int bodySize,
			Map<String, Object> var) {
		/**
Cache-Control:no-cache
Connection:Keep-Alive
Content-Length:29
Content-Type:text/plain; charset=utf-8
Date:Wed, 01 Feb 2012 08:06:33 GMT
Proxy-Connection:Keep-Alive
		 */
		ArrayList<String> header = new ArrayList<String>();
		header.add("Cache-Control:no-cache");
		header.add("Connection:Keep-Alive");
		header.add("Content-Length:" + bodySize);
		header.add("Content-Type:text/plain; charset=utf-8");
		header.add("Proxy-Connection:Keep-Alive");
		return null;
	}

	@Override
	boolean isGoOn(RequestSpy requestSpy) {
		return false;
	}

	@Override
	public boolean modifyResponse(WebConnection wc, RequestSpy rqSpy)
			throws IOException {
		return false;
	}


}
